﻿window.onload = function () {
    if (!document.getElementById("ace-settings-sidebar").checked) {
        $("#ace-settings-sidebar").trigger("click"); //固定左侧菜单
    }
    if (!document.getElementById("ace-settings-navbar").checked) {
        $("#ace-settings-navbar").trigger("click"); //固定头部导航栏
    }
    if (!document.getElementById("ace-settings-breadcrumbs").checked) {
        $("#ace-settings-breadcrumbs").trigger("click"); //固定子菜单
    }
    
    $('[data-rel=tooltip]').tooltip({ container: 'body' });
    $('[data-rel=popover]').popover({ container: 'body' });

    $('textarea[class*=autosize]').autosize({ append: "\n" });

    $('textarea.limited,input.limited').inputlimiter({
        remText: '当前还可输入 %n 个字符，',
        limitText: '最多 %n 个字符。'
    });

    $(".chosen-select").chosen();
};

function menuActive(name) {
    switch (name) {
        case "index":
            $("#menu0").addClass(" active");
            break;
        case "admin":
            $("#menu1").addClass(" active open");
            $("#menu11").addClass(" active");
            break;
        case "binding":
            $("#menu2").addClass(" active open");
            $("#menu21").addClass(" active");
        case "material":
            $("#menu2").addClass(" active open");
            $("#menu24").addClass(" active");
            break;
        
        default:
            break;
    }
}

function ajaxEngine(form, dataType, callback) {
    jQuery.ajax({
        url: form.action,
        type: form.method,
        dataType: dataType,
        data: jQuery(form).serialize(),
        success: callback
    });
}

function simpleAjax(url, dataType, data, callback) {
    jQuery.ajax({
        url: url,
        type: "POST",
        dataType: dataType,
        data: data,
        success: callback
    });
}

function logout() {
    layer.confirm("确认退出系统？未保存的数据将丢失！", function() {
        simpleAjax("/logout", "json", null, function (res) {
            switch (res.code) {
                case "N200":
                    window.location.href = res.returnurl;
                    break;
                default:
                    layer.msg(res.msg, 3, { type: 3 });
                    break;
            }
        });
    });
}